package com.ssyc.gsk_teacher.activity;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.ssyc.common.base.BaseActivity;
import com.ssyc.common.manager.BqaManager;
import com.ssyc.common.manager.PickChooseManager;
import com.ssyc.common.manager.SrfManager;
import com.ssyc.gsk_teacher.R;
import com.ssyc.gsk_teacher.adapter.RcPicAdapter;
import com.ssyc.gsk_teacher.bean.ScoreDetailsInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 展示成绩详情的界面
 * Created by Administrator on 2018/6/28 0028.
 */
public class TeacherShowScoreDetailsActivity extends BaseActivity implements View.OnClickListener {

    private ImageView ivBack;
    //标题
    private TextView tvTitle;
    private RecyclerView rv;
    private SmartRefreshLayout srf;

    //对应的学生对象
    private ScoreDetailsInfo.DataBean info;

    //头布局
    private View headView;
    //空视图
    private View emptyView;
    private RcPicAdapter adapter;

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.teacher_activity_show_score_details;
    }

    @Override
    protected void init() {
        showContent();
        //初始化视图
        initView();
        //获取传递对象
        initIntent();
        //初始化下下拉刷新控件
        initSrf();
        //设置里列表控件
        initRv();
    }


    /**
     * 初始化视图
     */
    public void initView() {
        ivBack = findViewById(R.id.iv_back);
        ivBack.setOnClickListener(this);
        tvTitle = findViewById(R.id.tv_st_title);
        rv = findViewById(R.id.rv);
        srf = findViewById(R.id.srf);
    }

    /**
     * 获取Intent传递的对象
     */
    private void initIntent() {

        info = (ScoreDetailsInfo.DataBean) getIntent().getSerializableExtra("student");
        if (null != info) {
            tvTitle.setText(info.getNAME());
        }
    }


    /**
     * 初始化下拉刷新控件
     */
    private void initSrf() {
        SrfManager.setSmartByPullListener(srf, null);
    }

    /**
     * 设置列表控件
     */
    private void initRv() {
        emptyView = View.inflate(this, R.layout.base_rv_common_empty_view, null);
        headView = View.inflate(this, R.layout.teacher_headview_show_score, null);
        TextView tvParent = headView.findViewById(R.id.tv_parent);
        TextView tvTeacher = headView.findViewById(R.id.tv_teacher);
        TextView tvScore = headView.findViewById(R.id.tv_score);
        //设置头布局的数据
        if (null != info) {
            tvScore.setText("测试分数:" + info.getSCORE());
            if (TextUtils.isEmpty(info.getPARENT_CONTENT())) {
                //家长回执
                tvParent.setText("暂无");
            } else {
                tvParent.setText(info.getPARENT_CONTENT());
            }

            if (TextUtils.isEmpty(info.getCONTENT())) {
                //教师评语
                tvTeacher.setText("暂无");
            } else {
                tvTeacher.setText(info.getCONTENT());
            }
        }


        //创建展示图片的列表的Url集合
        List<String> urls = new ArrayList<>();
        if (null != info) {
            if (!TextUtils.isEmpty(info.getPICTURE1())) {
                urls.add(info.getPIC_URL() + info.getPICTURE1());
            }

            if (!TextUtils.isEmpty(info.getPICTURE2())) {
                urls.add(info.getPIC_URL() + info.getPICTURE2());
            }

            if (!TextUtils.isEmpty(info.getPICTURE3())) {
                urls.add(info.getPIC_URL() + info.getPICTURE3());
            }

            if (!TextUtils.isEmpty(info.getPICTURE4())) {
                urls.add(info.getPIC_URL() + info.getPICTURE4());
            }
            if (!TextUtils.isEmpty(info.getPICTURE5())) {
                urls.add(info.getPIC_URL() + info.getPICTURE5());
            }
            if (!TextUtils.isEmpty(info.getPICTURE6())) {
                urls.add(info.getPIC_URL() + info.getPICTURE6());
            }

            if (!TextUtils.isEmpty(info.getPICTURE7())) {
                urls.add(info.getPIC_URL() + info.getPICTURE7());
            }

            if (!TextUtils.isEmpty(info.getPICTURE8())) {
                urls.add(info.getPIC_URL() + info.getPICTURE8());
            }

            if (!TextUtils.isEmpty(info.getPICTURE9())) {
                urls.add(info.getPIC_URL() + info.getPICTURE9());
            }

        }
        adapter = new RcPicAdapter(this, R.layout.tacher_rv_show_pic, urls);
        adapter.addHeaderView(headView);
        BqaManager.setRv(emptyView, this, adapter, rv);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                PickChooseManager.startShowBigActivity(TeacherShowScoreDetailsActivity.this, urls, position);
            }
        });

    }

    /**
     * 点击事件
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            //返回
            finish();
        }
    }
}
